package cn.wolfcode.luowowo.article.domain;

import cn.wolfcode.luowowo.common.domain.BaseDomain;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Getter@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Question extends BaseDomain {
    public static final int STATUS_RELEASE = 0; //正常
    public static final int STATUS_REMIND = 1;   //匿名

    private String title; //标题
    private String content; //提问内容
    private UserInfo author;//提问者
    private Destination dest; //目的地

    private WendaAnswer answer;//回答
    private List<WendaAnswer> wendaAnswers = new ArrayList<>(); //回答集合

    private int status;  //正常.匿名发布
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date questionTime; //发布时间
    private int viewnum; //问题浏览数.
    private int level; //回答者等级
    private int thumbupnum;//回答被顶数
    private int answernum;  //回答数
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date answerTime; //回答发布时间.

    private List<QuestionTag> tags = new ArrayList();
<<<<<<< Updated upstream
=======

    private String tagsName;

    public String getTagsName() {
        if (tags == null) {
            return null;
        }

        StringBuilder sb = new StringBuilder();
        for (QuestionTag tag : tags) {
            sb.append(tag.getName()).append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        tagsName = sb.toString();
        return tagsName;
    }

    public List<QuestionTag> getTags() {

        if (!StringUtils.hasLength(tagsName)) {
            return null;
        }
        //标签值的数组
        String[] vals = tagsName.split(",");
        tags = new ArrayList<>();
        for (int i = 0; i < vals.length; i++) {
            QuestionTag tag = new QuestionTag();
            tag.setName(vals[i]);
            tags.add(tag);
        }
        return tags;
    }
>>>>>>> Stashed changes
}

